package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {

    private TeacherDao teacherDao = new TeacherDao();

    public boolean isExists(String id) {

        boolean flag = false;

        Teacher[] allTeacher = teacherDao.getAllTeacher();
        for (int i = 0; i < allTeacher.length; i++) {
            if (allTeacher[i] != null && id.equals(allTeacher[i].getId())) {
                flag = true;
            }
        }
        return flag;
    }

    public boolean addTeacher(Teacher tea) {
        boolean flag = teacherDao.addTeacher(tea);
        return flag;
    }

    public Teacher[] getAllTeacher() {

        Teacher[] allTeacher = teacherDao.getAllTeacher();

        boolean flag = false;

        for (int i = 0; i < allTeacher.length; i++) {
            if (allTeacher[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag) {

            return allTeacher;

        } else {
            return null;
        }

    }

    public void delTeacher(String id) {
        teacherDao.delTeacher(id);

    }

    public void changeTeacher(String id, Teacher tea) {
        teacherDao.changeTeacher(id, tea);
    }
}
